package com.situ.dao;

import com.situ.bean.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {

    // 获取所有商品
    @Select("SELECT * FROM product")
    List<Product> getAllProducts();

    // 根据ID获取商品
    @Select("SELECT * FROM product WHERE id = #{id}")
    Product getProductById(int id);

    // 添加商品
    @Insert("INSERT INTO product (name, price, oldprice, info, categoryid, state, defaultimg, imgurl) " +
            "VALUES (#{name}, #{price}, #{oldprice}, #{info}, #{categoryid}, #{state}, #{imgurl})")
    void addProduct(Product product);

    // 更新商品
    @Update("UPDATE product SET name = #{name}, price = #{price}, oldprice = #{oldprice}, info = #{info}, " +
            "categoryid = #{categoryid}, state = #{state}, imgurl = #{imgurl} " +
            "WHERE id = #{id}")
    void updateProduct(Product product);

    // 删除商品
    @Delete("DELETE FROM product WHERE id = #{id}")
    void deleteProduct(int id);
}